package com.zsc.wxapp.mapper;

import com.github.pagehelper.Page;
import com.zsc.wxapp.annotation.AutoFill;
import com.zsc.wxapp.entity.PriceTime;
import com.zsc.wxapp.entity.dto.PricePageDTO;
import com.zsc.wxapp.enumeration.OperationType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface PriceTimeMapper {

    /**
     * 查询某天的卷烟价格数据
     * @param date 日期
     * @return List<PriceTime>
     */
    @Select("select * from price_time where create_time = #{date}")
    List<PriceTime> getPriceTime(LocalDate date);

    /**
     * 插入当天的卷烟价格数据
     * @param priceTime 卷烟价格
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(PriceTime priceTime);

    /**
     * 分页查询数据
     * @param pricePageDTO
     * @return
     */
    Page<PriceTime> PageQuery(PricePageDTO pricePageDTO);

    /**
     * 根据商品名称获取商品在某一天的数据
     * @param name
     * @param date
     * @return
     */
    @Select("select * from price_time where product_name = #{name} and create_time = #{date} limit 1")
    PriceTime getPriceTimeByName(String name, LocalDate date);

    /**
     * 根据id获取到卷烟代码
     * @param id
     * @return
     */
    @Select("select product_code from price_time where id = #{id} limit 1")
    String getPriceTimeById(Integer id);

    /**
     * 根据卷烟名称获取到近日卷烟价格
     * @param productCode 卷烟代码
     * @return List
     */
    @Select("select * from price_time where product_code = #{productCode} order by create_time asc")
    List<PriceTime> getPriceTimeList(String productCode);

    @Select("select * from price_time where create_time = #{createTime}")
    List<PriceTime> priceTimePage(LocalDate createTime);

}
